<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 7、输入年月,输出月份的最大天数(月份在1-12之间,输入错误要重输)

    // 声明年月
    let year = +prompt('请输入年：');
    let month = 0;

    // 天数数组
    let arr = [31, year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    
    // 如果输入月不在 1~12 中
    while (-1 == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].indexOf(month)) {
        month = +prompt('请输入月（1~12）：');
    }

    // 弹窗输出
    alert(`${year}年${month}月最大天数是${arr[month - 1]}天`);
</script>

</html>